using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Blople.GameComponents
{
    public class RumblePad : Microsoft.Xna.Framework.GameComponent
    {
        private int time;
        private int startTickCount;

        public RumblePad(Game game) : base(game)
        { }

        public override void Initialize()
        {
            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            if (time > 0)
            {
                int elapsed = System.Environment.TickCount - startTickCount;
                if (elapsed >= time)
                {
                    time = 0;
                    GamePad.SetVibration(PlayerIndex.One, 0, 0);
                }
            }
            base.Update(gameTime);
        }

        public void Rumble(int time, float leftMotor, float rightMotor)
        {
            startTickCount = System.Environment.TickCount;
            this.time = time;
            GamePad.SetVibration(PlayerIndex.One, leftMotor, rightMotor);
        }

    }
}
